package com.banzhi.shop.activity;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.banzhi.shop.MyApp;

import com.banzhi.shop.R;
import com.banzhi.shop.base.BaseActivity;
import com.banzhi.shop.entity.InviteShopkeeperShare.InviteShopKeeperCallBack;
import com.banzhi.shop.entity.InviteShopkeeperShare.InviteShopKeeperImpl;
import com.banzhi.shop.entity.InviteShopkeeperShare.Share_Data;
import com.banzhi.shop.entity.Store.Store_Data;
import com.banzhi.shop.entity.WXshare;
import com.banzhi.shop.fragment.StoreFrg;
import com.banzhi.shop.model.CallBack.StoreFrgCallBack;
import com.banzhi.shop.model.CallBack.WXshareCallBack;
import com.banzhi.shop.model.Impl.StoreFrgImpl;
import com.banzhi.shop.model.Impl.WXshareImpl;
import com.banzhi.shop.model.WXshareModel;
import com.banzhi.shop.state.URLString;
import com.banzhi.shop.utils.EndlessRecyclerOnScrollListener;
import com.banzhi.shop.utils.LoadingDialogUtils;
import com.banzhi.shop.utils.LogUtils;
import com.banzhi.shop.utils.NoTokenUtils;
import com.banzhi.shop.utils.NumberUtils;
import com.banzhi.shop.utils.ShareUtils;
import com.banzhi.shop.utils.ToastUtils;
import com.banzhi.shop.utils.Translucent;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.github.library.BaseRecyclerAdapter;
import com.github.library.BaseViewHolder;
import com.github.library.listener.OnRecyclerItemClickListener;

import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

import static com.banzhi.shop.MyApp.context;

//邀请店长
public class InviteShopkeeperShareActivity extends BaseActivity implements InviteShopKeeperCallBack,WXshareCallBack, View.OnClickListener, StoreFrgCallBack {

    private ImageView            mIvBack2;

    private SwipeRefreshLayout mSrlRvList;
    private List<Share_Data> mSharedatas = new ArrayList<>();
    private int page=1;
    /**
     * 用于存储该商品的
     */
    // private String         wxURL;
    private static final int PENGYOUQUAN  = 1;
    private static final int WEIXINHAOYOU = 2;
    private static final int LIANJIE      = 3;
    private static final int ERWEIMA      = 4;
    private ImageView            mIvShare2;
    private RecyclerView mRvList;
    private LinearLayoutManager mLLM;
    private InviteShopKeeperImpl mISK;

    private WXshareModel wxmodel;

    private String       wxURL;

    private int        position;
    private Share_Data share_data;
    private RelativeLayout rlnodata;

    private int type;


    private LinearLayoutManager mLinearLayoutManager;
    private BaseRecyclerAdapter<Share_Data> mAdapter;
    private StoreFrgImpl model;
    private Store_Data data;
    private ImageView mIvHead2;
    private ImageView mIvHead1;
    private ImageView mIvHead3;
    private ImageView mIvFoot3;
    private ImageView mIvFoot1;
    private ImageView mIvFoot2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate( savedInstanceState );
        setContentView( R.layout.activity_invite_shopkeeper_share );
        Translucent.setTranslucent( this );
        setinits();
        setListeners();
        wxmodel = new WXshareImpl();
        mISK = new InviteShopKeeperImpl();
        LoadingDialogUtils.showProgress( this, "正在加载,请稍后~" );
        mISK.getData( page,this );

        model = new StoreFrgImpl();
        model.getData(this);
    }

    @Override
    protected void onStart() {
        super.onStart();
    }
    private void setinits() {

        mIvBack2= (ImageView) findViewById(R.id.iv_back2);
        mIvShare2 = (ImageView) findViewById( R.id.iv_share2 );
        mSrlRvList = (SwipeRefreshLayout) findViewById( R.id.srl_rv_list );
        mSrlRvList.setColorSchemeResources(R.color.themeColor);
        mSrlRvList.setProgressBackgroundColorSchemeResource(R.color.colorWhite);
        mLinearLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
        mRvList = (RecyclerView) findViewById( R.id.rv_list );
        mRvList.setLayoutManager( mLinearLayoutManager);
    //    rlnodata = (RelativeLayout) findViewById(R.id.rl_nodata2);
    }
    private void setListeners() {
        mIvBack2.setOnClickListener( this );
        mIvShare2.setOnClickListener( this );
        mRvList.setOnClickListener( this );
        mSrlRvList.setOnRefreshListener( new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                page=1;
                mISK.getData( page,InviteShopkeeperShareActivity.this );
                mAdapter.notifyDataSetChanged();
                mSrlRvList.setRefreshing( false );//刷新图标消失
            }
        } );
        mRvList.addOnScrollListener(new EndlessRecyclerOnScrollListener( mLinearLayoutManager) {
            @Override
            public void onLoadMore() {
       /*         page++;
                LoadingDialogUtils.showProgress(InviteShopkeeperShareActivity.this, "正在加载,请稍后~");
                mISK.getData( page,InviteShopkeeperShareActivity.this );*/
            }
        });


    }

    @Override
    public void ongetDataError(Object object) {
        if (mSrlRvList.isRefreshing()) {
            mSrlRvList.setRefreshing(false);
        }
        JSONObject jsonObject = (JSONObject) object;
        NoTokenUtils.loginOut(this, jsonObject);
        ToastUtils.makeToastShort(jsonObject.optString("msg"));

    }

    @Override
    public void ongetWXdataSuccess(Object object, int num) {
        LoadingDialogUtils.dismiss();
        WXshare share = (WXshare) object;
        wxURL = share.getRes();
        if(type==3){
            if (num == LIANJIE) {
                ShareUtils.copyLianjie(this, wxURL);
            } else if (num == ERWEIMA) {
                ShareUtils.ereima3(this, mSharedatas.get(position).getTitle(), mSharedatas.get(position).getMarketprice(), null, null, null, mSharedatas.get(position).getThumb(), wxURL);
            } else if (num == WEIXINHAOYOU) {
                ShareUtils.wxshare(mSharedatas.get(position).getTitle(), mSharedatas.get(position).getThumb_url().get(0), "全球十佳网商联合出品。匠心工厂，源头供货，正品优品，尽在半职。", wxURL);
            } else if (num == PENGYOUQUAN) {
                ShareUtils.wxPengyouquan(mSharedatas.get(position).getTitle(), mSharedatas.get(position).getThumb(), wxURL);
            }
        }else if(type==4){
            if (num == LIANJIE) {
                ShareUtils.copyLianjie(InviteShopkeeperShareActivity.this, wxURL);
            } else if (num == WEIXINHAOYOU) {
                ShareUtils.wxshare(MyApp.loginMessage.getString("nickname", "") + "邀请您加入半职VIP，消费省钱，分享赚钱", MyApp.loginMessage.getString("personAvatar", ""), "全球十佳网商联合出品。匠心工厂，源头供货，正品优品，尽在半职。", wxURL);
            } else if (num == PENGYOUQUAN) {
                ShareUtils.wxPengyouquan("半职", null, wxURL);
            } else if (num == ERWEIMA) {
                ShareUtils.ereimakaidian6(InviteShopkeeperShareActivity.this, MyApp.loginMessage.getString("nickname", "") + "邀请您加入半职", "", null, null, null, MyApp.loginMessage.getString("ShopLogo", ""), wxURL);
            }

        }else if ( type == 5 ){
            if (num == LIANJIE) {
                ShareUtils.copyLianjie(InviteShopkeeperShareActivity.this, wxURL);
            } else if (num == WEIXINHAOYOU) {
                ShareUtils.wxshare(MyApp.loginMessage.getString("ShopName", ""), MyApp.loginMessage.getString("personAvatar", ""), "全球十佳网商联合出品。匠心工厂，源头供货，正品优品，尽在半职。", wxURL);
            } else if (num == PENGYOUQUAN) {
                ShareUtils.wxPengyouquan(data.getShopName(), data.getShopLogo(), wxURL);
            } else if (num == ERWEIMA) {
                ShareUtils.ereimakaidian6(InviteShopkeeperShareActivity.this, MyApp.loginMessage.getString("ShopName", ""), "", null, null, null, data.getShopLogo(), wxURL);
            }

        }

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_back2:
                finish();
                break;
            case R.id.iv_share2:
                wxURL = null;
                type=4;
                showSharePopupwindow();
                break;
        }
    }

    private void showSharePopupwindow() {
        //设置contentView
        View contentView = LayoutInflater.from( InviteShopkeeperShareActivity.this ).inflate( R.layout.popupwindow_share_dianzhu, null );
        final PopupWindow popWindow = new PopupWindow( contentView, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT, true );
        popWindow.setContentView( contentView );
        popWindow.setAnimationStyle( R.style.AnimBottom );

        popWindow.setFocusable( true );
        popWindow.setOutsideTouchable( false );// 设置允许在外点击消失
        //设置各个控件的点击响应
        ImageView ivchacha = (ImageView) contentView.findViewById( R.id.iv_chacha );
        LinearLayout llpengyouquan = (LinearLayout) contentView.findViewById( R.id.ll_pengyouquan );
        LinearLayout llweixin = (LinearLayout) contentView.findViewById( R.id.ll_weixing );
        LinearLayout lllianjie = (LinearLayout) contentView.findViewById( R.id.ll_lianjie );
        LinearLayout llerweima = (LinearLayout) contentView.findViewById( R.id.ll_erweima );
        RelativeLayout rlbackground = (RelativeLayout) contentView.findViewById( R.id.rl_background );
        LinearLayout ll = (LinearLayout) contentView.findViewById( R.id.ll );
        rlbackground.setOnClickListener( new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popWindow.dismiss();
            }
        } );
        ll.setOnClickListener( new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        } );
        lllianjie.setOnClickListener( new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (wxURL == null) {
                    LoadingDialogUtils.showProgress( InviteShopkeeperShareActivity.this, "正在加载,请稍后~" );
                    wxmodel.getData( null, "3", LIANJIE, InviteShopkeeperShareActivity.this );
                } else {
                    ShareUtils.copyLianjie( InviteShopkeeperShareActivity.this, wxURL );
                }
            }
        } );
        llweixin.setOnClickListener( new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (wxURL == null) {
                    LoadingDialogUtils.showProgress( InviteShopkeeperShareActivity.this, "正在加载,请稍后~" );
                    wxmodel.getData( null, "3", WEIXINHAOYOU, InviteShopkeeperShareActivity.this );
                } else {
                    ShareUtils.wxshare( MyApp.loginMessage.getString( "nickname", "" ) + "邀请您加入半职VIP，消费省钱，分享赚钱", MyApp.loginMessage.getString( "personAvatar", "" ), "全球十佳网商联合出品。匠心工厂，源头供货，正品优品，尽在半职。", wxURL );
                }
            }
        } );
        llpengyouquan.setOnClickListener( new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (wxURL == null) {
                    LoadingDialogUtils.showProgress( InviteShopkeeperShareActivity.this, "正在加载,请稍后~" );
                    wxmodel.getData( null, "3", PENGYOUQUAN, InviteShopkeeperShareActivity.this );
                } else {
                    ShareUtils.wxPengyouquan( MyApp.loginMessage.getString( "nickname", "" ) + "邀请您加入半职VIP，消费省钱，分享赚钱", null, wxURL );
                }
            }
        } );
        llerweima.setOnClickListener( new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (wxURL == null) {
                    LoadingDialogUtils.showProgress( InviteShopkeeperShareActivity.this, "正在加载,请稍后~" );

                    wxmodel.getData( null, "3", ERWEIMA, InviteShopkeeperShareActivity.this );
                } else {
                    ShareUtils.ereimakaidian6( InviteShopkeeperShareActivity.this, MyApp.loginMessage.getString( "nickname", "" ) + "邀请您加入半职", "", null, null, null, MyApp.loginMessage.getString( "ShopLogo", "" ), wxURL );

                }
            }
        } );
        ivchacha.setOnClickListener( new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popWindow.dismiss();
            }
        } );
        ColorDrawable dw = new ColorDrawable( 0x70000000 );
        popWindow.setBackgroundDrawable( dw );
        popWindow.showAtLocation( contentView, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0 );
     /*   popWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                //在每次popupuwindow  dissmiss的时候吧wxURL设置为空  保证下次弹别的商品的popupwindow的时候wxURL是等于null的
                wxURL = null;
            }
        });*/

    }



    @Override
    public void ongetDataSuccess(Object object) {
        if (mSrlRvList.isRefreshing()) {
            mSrlRvList.setRefreshing(false);
        }
        List<Share_Data> shareDataList = (List<Share_Data>) object;
        if (page == 1) {
            mSharedatas.clear();
        } else {
            if (shareDataList.size() == 0) {

                return;
            }
        }
        mSharedatas.clear();
        mSharedatas.addAll(shareDataList);

        showView();
        LoadingDialogUtils.dismiss();
        mRvList.setBackgroundColor(getResources().getColor(R.color.themeColor3));
        //

    }



    private void showView() {

        mAdapter = new BaseRecyclerAdapter<Share_Data>(this, mSharedatas, R.layout.recyclerview_share_items) {

            @Override
            protected void convert(final BaseViewHolder baseViewHolder, final Share_Data share_data) {
                baseViewHolder.setText(R.id.tv_title, share_data.getTitle())
                        .setText(R.id.tv_subtitle, share_data.getSubtitle())
                        .setText(R.id.tv_market_price, share_data.getMarketprice())
                        .setText(R.id.tv_liyun1, share_data.getProfit());
                Glide.with(mContext).load(share_data.getThumb()).placeholder(R.mipmap.recyclerview_item).into((ImageView) baseViewHolder.getView(R.id.iv_title_pic));
                baseViewHolder.setOnClickListener(R.id.iv_xianqing1,new View.OnClickListener(){
                    @Override
                    public void onClick(View view) {
                        //素材页面
                        Intent intent = new Intent(InviteShopkeeperShareActivity.this, InviteShopKeeperShareDetailsActivity.class);
                        //减去头部
                        int adapterPosition = baseViewHolder.getAdapterPosition()-1;
                        intent.putExtra( "id", mSharedatas.get(adapterPosition).getId() + "" );
                        intent.putExtra("type", "1");
                        startActivity(intent);
                    }
                });
                baseViewHolder.setOnClickListener(R.id.iv_fenxiang1,new View.OnClickListener(){
                    @Override
                    public void onClick(View view) {
                        int adapterPosition = baseViewHolder.getAdapterPosition()-1;
                        //分享
                        wxURL = null;
                        type=3;
                        showSharePopupwindow(share_data);
                        InviteShopkeeperShareActivity.this.position = adapterPosition;

                    }
                });
            }

        };
        mAdapter.setOnRecyclerItemClickListener(new OnRecyclerItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {
                //跳转详情页面
                Intent intent = new Intent( InviteShopkeeperShareActivity.this, InviteShopKeeperShareDetailsActivity.class );
                intent.putExtra( "id", mSharedatas.get( position ).getId() + "" );
                startActivity( intent );

            }
        });
        mRvList.setAdapter(mAdapter);
        mAdapter.notifyDataSetChanged();
        mAdapter.openLoadAnimation(false); //false 不使用动画；
        addHeaderView();
        addFooterView();

    }

    private void addHeaderView() {
        LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View headerView = mInflater.inflate(R.layout.rv_head, null);
        mIvHead1 = (ImageView) headerView.findViewById(R.id.iv_head);
        mIvHead2 = (ImageView) headerView.findViewById(R.id.iv_head2);
        mIvHead3 = (ImageView) headerView.findViewById(R.id.iv_head3);

        Glide.with(this).load(URLString.Head1Url).skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE).into( mIvHead1);
        Glide.with(this).load(URLString.Head2Url).skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE).into( mIvHead2);
        Glide.with(this).load(URLString.Head3Url).skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE).into( mIvHead3);
        headerView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        mAdapter.addHeaderView(headerView);
        mIvHead2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                wxURL = null;
                type=5;
                showSharePopupwindow5();
            }
        });
    }

   private void addFooterView() {
        LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View footerView = mInflater.inflate(R.layout.rv_foot, null);
       mIvFoot1 = (ImageView) footerView.findViewById(R.id.iv_foot1);
       mIvFoot2 = (ImageView) footerView.findViewById(R.id.iv_foot2);
       mIvFoot3 = (ImageView) footerView.findViewById(R.id.iv_foot3);
       Glide.with(this).load(URLString.Foot1Url).skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE).into( mIvFoot1);
       Glide.with(this).load(URLString.Foot2Url).skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE).into( mIvFoot2);
       Glide.with(this).load(URLString.Foot3Url).skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE).into( mIvFoot3);

       footerView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
       mAdapter.addFooterView(footerView);
   /*    ivFoot3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                wxURL = null;
                type=5;
                showSharePopupwindow5();
            }
        });*/

    }

    private void showSharePopupwindow5() {
        //设置contentView
        View contentView = LayoutInflater.from(InviteShopkeeperShareActivity.this).inflate(R.layout.popupwindow_share_dianzhu, null);
        final PopupWindow popWindow = new PopupWindow(contentView, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT, true);
        popWindow.setContentView(contentView);
        popWindow.setAnimationStyle(R.style.AnimBottom);

        popWindow.setFocusable(true);
        popWindow.setOutsideTouchable(false);// 设置允许在外点击消失

        ImageView ivchacha = (ImageView) contentView.findViewById(R.id.iv_chacha);
        LinearLayout llpengyouquan = (LinearLayout) contentView.findViewById(R.id.ll_pengyouquan);
        LinearLayout llweixin = (LinearLayout) contentView.findViewById(R.id.ll_weixing);
        LinearLayout lllianjie = (LinearLayout) contentView.findViewById(R.id.ll_lianjie);
        LinearLayout llerweima = (LinearLayout) contentView.findViewById(R.id.ll_erweima);
        RelativeLayout rlbackground = (RelativeLayout) contentView.findViewById(R.id.rl_background);
        LinearLayout ll = (LinearLayout) contentView.findViewById(R.id.ll);
        rlbackground.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popWindow.dismiss();
            }
        });
        ll.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
        lllianjie.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (wxURL == null) {
                    LoadingDialogUtils.showProgress(InviteShopkeeperShareActivity.this, "正在加载,请稍后~");
                    wxmodel.getData(null, "2", LIANJIE, InviteShopkeeperShareActivity.this);
                } else {
                    ShareUtils.copyLianjie(InviteShopkeeperShareActivity.this, wxURL);
                }
            }
        });
        llweixin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (wxURL == null) {
                    LoadingDialogUtils.showProgress(InviteShopkeeperShareActivity.this, "正在加载,请稍后~");
                    wxmodel.getData(null, "2", WEIXINHAOYOU, InviteShopkeeperShareActivity.this);
                } else {
                    ShareUtils.wxshare(MyApp.loginMessage.getString("ShopName", "") ,  data.getShopLogo(), "全球十佳网商联合出品。匠心工厂，源头供货，正品优品，尽在半职。", wxURL);
                }
            }
        });
        llpengyouquan.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (wxURL == null) {
                    LoadingDialogUtils.showProgress(InviteShopkeeperShareActivity.this, "正在加载,请稍后~");
                    wxmodel.getData(null, "2", PENGYOUQUAN, InviteShopkeeperShareActivity.this);
                } else {
                    ShareUtils.wxPengyouquan(data.getShopName(), data.getShopLogo(), wxURL);
                }
            }
        });
        llerweima.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (wxURL == null) {
                    LoadingDialogUtils.showProgress(InviteShopkeeperShareActivity.this, "正在加载,请稍后~");
                    wxmodel.getData(null, "2", ERWEIMA, InviteShopkeeperShareActivity.this);
                } else {
                    ShareUtils.ereimakaidian6(InviteShopkeeperShareActivity.this, MyApp.loginMessage.getString("ShopName", ""), "", null, null, null, data.getShopLogo(), wxURL);
                }
            }
        });
        ivchacha.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                wxURL = null;
                popWindow.dismiss();
            }
        });
        ColorDrawable dw = new ColorDrawable(0x70000000);
        popWindow.setBackgroundDrawable(dw);
        popWindow.showAtLocation(contentView, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);

    }



    @Override
    public void ongetWXdataError(Object object, int num) {
        JSONObject jsonObject = (JSONObject) object;
        NoTokenUtils.loginOut( this, jsonObject );
    }


    private void showSharePopupwindow(final Share_Data share_data) {
        //设置contentView
        View contentView = LayoutInflater.from(this).inflate(R.layout.popupwindow_share_goods, null);
        final PopupWindow popWindow = new PopupWindow(contentView, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT, true);
        popWindow.setContentView(contentView);
        popWindow.setAnimationStyle(R.style.AnimBottom);

        popWindow.setFocusable(true);
        popWindow.setOutsideTouchable(false);// 设置允许在外f点击消失

        //设置各个控件的点击响应
        ImageView ivchacha = (ImageView) contentView.findViewById(R.id.iv_chacha);
        TextView mTvprice = (TextView) contentView.findViewById( R.id.tvmoney );
        TextView tvpricetwo = (TextView) contentView.findViewById(R.id.tv_money_two);
        LinearLayout llpengyouquan = (LinearLayout) contentView.findViewById(R.id.ll_pengyouquan);
        LinearLayout llweixin = (LinearLayout) contentView.findViewById(R.id.ll_weixing);
        LinearLayout lllianjie = (LinearLayout) contentView.findViewById(R.id.ll_lianjie);
        LinearLayout llerweima = (LinearLayout) contentView.findViewById(R.id.ll_erweima);
        RelativeLayout rlbackground = (RelativeLayout) contentView.findViewById(R.id.rl_background);
        LinearLayout ll = (LinearLayout) contentView.findViewById(R.id.ll);
        rlbackground.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popWindow.dismiss();
            }
        });
        ll.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
        if (share_data != null) {
            mTvprice.setText( NumberUtils.DecimalFormat( share_data.getProfit()));
            tvpricetwo.setText(NumberUtils.DecimalFormat(share_data.getProfit()));
            lllianjie.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    if (wxURL == null) {
                        LoadingDialogUtils.showProgress(InviteShopkeeperShareActivity.this, "正在加载,请稍后~");
                       wxmodel.getData(share_data.getId(), null, LIANJIE, InviteShopkeeperShareActivity.this);
                    } else {
                        ShareUtils.copyLianjie(InviteShopkeeperShareActivity.this, wxURL);
                    }
                }
            });
            llerweima.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (wxURL == null) {
                        LoadingDialogUtils.showProgress(InviteShopkeeperShareActivity.this, "正在加载,请稍后~");
                        wxmodel.getData(share_data.getId(), null, ERWEIMA, InviteShopkeeperShareActivity.this);
                    } else {
                        ShareUtils.ereima3(InviteShopkeeperShareActivity.this, share_data.getTitle(), share_data.getMarketprice(), null, null, null, share_data.getThumb(), wxURL);
                    }
                }
            });
            llweixin.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (wxURL == null) {
                        LoadingDialogUtils.showProgress(InviteShopkeeperShareActivity.this, "正在加载,请稍后~");
                        wxmodel.getData(share_data.getId(), null, WEIXINHAOYOU, InviteShopkeeperShareActivity.this);
                    } else {
                        ShareUtils.wxshare(share_data.getTitle(), share_data.getThumb_url().get(0),  "全球十佳网商联合出品。匠心工厂，源头供货，正品优品，尽在半职。", wxURL);
                        LogUtils.d("share_data.getThumb_url().get(0):", share_data.getThumb_url().get(0));
                    }
                }
            });
            llpengyouquan.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (wxURL == null) {
                        LoadingDialogUtils.showProgress(InviteShopkeeperShareActivity.this, "正在加载,请稍后~");
                        wxmodel.getData(share_data.getId(), null, PENGYOUQUAN, InviteShopkeeperShareActivity.this);
                    } else {
                        ShareUtils.wxPengyouquan(share_data.getTitle(), share_data.getThumb(), wxURL);
                    }
                }
            });
        }
        ivchacha.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                wxURL = null;
                popWindow.dismiss();
            }
        });
        ColorDrawable dw = new ColorDrawable(0x70000000);
        popWindow.setBackgroundDrawable(dw);
        popWindow.showAtLocation(contentView, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
      /*  popWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                //在每次popupuwindow  dissmiss的时候吧wxURL设置为空  保证下次弹别的商品的popupwindow的时候wxURL是等于null的
                wxURL = null;
            }
        });*/
    }

    @Override
    public void ongetStoreFrgDataSuccess(Object object) {
        LoadingDialogUtils.dismiss();
        data = (Store_Data) object;
        SharedPreferences.Editor editor = MyApp.loginMessage.edit();
        editor.putString("ShopName", data.getShopName());
        editor.putString("ShopLogo", data.getShopLogo());
        editor.apply();
    }

    @Override
    public void ongetStoreFrgDataError(Object object) {
        JSONObject jsonObject = (JSONObject) object;
        NoTokenUtils.loginOut(InviteShopkeeperShareActivity.this, jsonObject);
        ToastUtils.makeToastShort(jsonObject.optString("msg"));
    }
}
